package com.yulan.binary;

import org.junit.Test;

import java.util.Arrays;

/**
 * 1099. 小于 K 的两数之和
 */
public class LeetCode_1099 {
    public int twoSumLessThanK(int[] A, int K) {
        Arrays.sort(A);
        int left = 0, right = A.length - 1;
        int res = -1;
        while(left<right){
            //向右规约 --- 贪心
            if(A[left] + A[right] < K){
                res = Math.max(A[left]+A[right],res);
                left++;
            }else{
                right--;
            }
        }
        return res;
    }

    @Test
    public void test(){
        int[] arr = {34,23,1,24,75,33,54,8};
        int k = 60;
        System.out.println(twoSumLessThanK(arr,k));
    }
}
